﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Structural_Patterns.Facade_Pattern
{
    public class FacadePattern : IPatternDemonstrate
    {
        public void StructuralCode()
        {
            Facade facade = new Facade();

            facade.MethodA();
            facade.MethodB();
        }

        public string PatternDescription()
        {
            string description = @"
Definition
Provide a unified interface to a set of interfaces in a subsystem. 
Façade defines a higher-level interface that makes the subsystem easier to use.

Participants

  The classes and objects participating in this pattern are:

Facade   (MortgageApplication)
·knows which subsystem classes are responsible for a request.
·delegates client requests to appropriate subsystem objects.

Subsystem classes   (Bank, Credit, Loan)
·implement subsystem functionality.
·handle work assigned by the Facade object.
·have no knowledge of the facade and keep no reference to it.";
            return description;
        }

        public void RealWorldExample()
        {
            // Facade
            Mortgage mortgage = new Mortgage();

            // Evaluate mortgage eligibility for customer
            Customer customer = new Customer("Ann McKinsey");
            bool eligible = mortgage.IsEligible(customer, 125000);

            Console.WriteLine("\n" + customer.Name +
                " has been " + (eligible ? "Approved" : "Rejected"));
        }
    }
}
